export default {
  mounted: (el, binding, vnode) => {
    // setup数据在instance中可以获取到
    // console.log('instance', binding.instance.clickButton())
    // console.log('instance', binding.instance.index)
    let throttleTime = binding.value // 防抖时间
    if (!throttleTime) { // 用户若不设置防抖时间，则默认2s
      throttleTime = 2000
    }
    let cbFun
    el.addEventListener('click', event => {
      if (!cbFun) { // 第一次执行
        cbFun = setTimeout(() => {
          cbFun = null
        }, throttleTime)
      } else {
        event && event.stopImmediatePropagation()
      }
    }, true)
  }
}
